<?php

namespace App\Http\Resources\nursery;


use App\Models\goods\ShopCar;
use App\Models\nursery\Major;
use App\Models\nursery\UserMajor;
use App\Models\User;
use Illuminate\Http\Resources\Json\ResourceCollection;

class UserMajorCollection extends ResourceCollection
{


    public function __construct( $resource)
    {
        parent::__construct($resource);
        $this->resource = $this->collectResource($resource);
    }


    /**
     * Transform the resource collection into an array.
     *
     * @return \Illuminate\Support\Collection
     */
    public function toArray($request)
    {
        return $this->collection->map(function (Major $item) {
            return [
                'id' => $item->id,
                'img' => $item->img,
                'name' => $item->name??'',
                'num' => $item->user_major->num,
                'price' => $item->user_major->price,
            ];
        });
    }
}
